import java.util.ArrayList;
import java.util.List;
import java.util.Scanner;

class StudentManager {
    private List<String> students = new ArrayList<>();
    private RandomPicker randomPicker;

    public StudentManager() {
        // 添加一些默认学生
        students.add("学生 1");
        students.add("学生 2");
        students.add("学生 3");
        students.add("学生 4");
        students.add("学生 5");
        students.add("学生 6");
    }

    // 返回学生姓名列表
    public List<String> getStudents() {
        return students;
    }

    // 设置RandomPicker实例，以便能调用其方法
    public void setRandomPicker(RandomPicker randomPicker) {
        this.randomPicker = randomPicker;
    }

    public void manageStudents(Scanner scanner) {
        System.out.println("学生管理");
        System.out.println("1. 增删学生");
        System.out.println("2. 维护学生");
        System.out.println("3. 学生列表");
        System.out.print("请选择操作: ");
        int choice = scanner.nextInt();
        scanner.nextLine(); // 清除换行符

        switch (choice) {
            case 1:
                System.out.println("增删学生");
                System.out.println("1. 新增学生");
                System.out.println("2. 删除学生");
                System.out.print("请选择操作: ");
                int addOrDeleteChoice = scanner.nextInt();
                scanner.nextLine(); // 清除换行符

                switch (addOrDeleteChoice) {
                    case 1:
                        System.out.print("输入学生姓名: ");
                        String studentName = scanner.nextLine();
                        students.add(studentName);
                        System.out.println("学生 " + studentName + " 已新增");
                        break;
                    case 2:
                        System.out.print("输入要删除的学生姓名: ");
                        String studentToDelete = scanner.nextLine();

                        if (students.contains(studentToDelete)) {
                            students.remove(studentToDelete);
                            System.out.println("学生 " + studentToDelete + " 已删除");
                        } else {
                            System.out.println("学生 " + studentToDelete + " 不存在");
                        }
                        break;
                    default:
                        System.out.println("无效选择");
                }
                break;
            case 2:
                System.out.println("记录学生成绩");
                System.out.println("1. 输入学生成绩");
                System.out.print("请选择操作: ");
                int recordChoice = scanner.nextInt();
                scanner.nextLine(); // 清除换行符

                if (recordChoice == 1) {
                    System.out.print("输入学生姓名: ");
                    String studentNameForScore = scanner.nextLine();

                    if (students.contains(studentNameForScore)) {
                        System.out.print("输入该学生的成绩: ");
                        double score = scanner.nextDouble();
                        scanner.nextLine(); // 清除换行符

                        // 调用RandomPicker的recordStudentScore方法记录成绩
                        randomPicker.recordStudentScore(studentNameForScore, score);

                        System.out.println("已记录学生 " + studentNameForScore + " 的成绩为 " + score);
                    } else {
                        System.out.println("学生 " + studentNameForScore + " 不存在");
                    }
                } else {
                    System.out.println("无效选择");
                }
                break;
            case 3:
                System.out.println("学生列表:");
                for (String s : students) {
                    System.out.println(s);
                }
                break;
            default:
                System.out.println("无效选择");
        }
    }
}